<template>
  <el-dialog :title="title" :visible="visible" @close="visible=false">
    <el-form
      ref="form"
      :model="entityData"
      :rules="rules"
      label-width="80px"
      label-position="right"
      style="width:90%;margin:0px auto;"
    >
      <!--表单区域 -->
      <el-form-item label="组织机构" prop="parentId">
        <organization-single-select
          v-model="entityData.organizationId"
          :name="entityData.organizationName"
          @changeSelect="changeSelect"
        />
      </el-form-item>
      <el-form-item label="账号" prop="account">
        <el-input v-model="entityData.account" />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="entityData.name" />
      </el-form-item>
      <el-form-item label="职务" prop="position">
        <el-input v-model="entityData.position" />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <dictionary-radio-group
          v-model="entityData.gender"
          :code="constant.DICTIONARY_TYPE_CODES.GENDER"
        />
      </el-form-item>
      <el-form-item label="出生日期" prop="birthday">
        <el-date-picker
          v-model="entityData.birthday"
          value-format="yyyy-MM-dd HH:mm:ss"
          format="yyyy年MM月dd日"
          type="date"
          placement="bottom-end"
          placeholder="请选择"
          class="form-item"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="telephone">
        <el-input v-model="entityData.telephone" />
      </el-form-item>
      <el-form-item label="邮箱地址" prop="email">
        <el-input v-model="entityData.email" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <dictionary-radio-group
          v-model="entityData.status"
          :code="constant.DICTIONARY_TYPE_CODES.STATUS"
        />
      </el-form-item>
      <el-form-item label="排序号" prop="orderNo">
        <el-input v-model="entityData.orderNo" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button v-show="saveButtonVisible" type="primary" @click="save">保存</el-button>
      <el-button @click="close">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { detailMixin } from '@/mixin/detailMixin'
const MODULE_CODE = 'system'
const ENTITY_TYPE = 'user'
export default {
  name: ENTITY_TYPE + '-detail',
  mixins: [detailMixin],
  props: {
    parentId: {
      type: String,
      default: '',
      required: false
    },
    parentName: {
      type: String,
      default: '',
      required: false
    }
  },
  data() {
    return {
      entityType: ENTITY_TYPE,
      moduleCode: MODULE_CODE,
      // eslint-disable-next-line no-eval
      api: eval('this.$api.' + MODULE_CODE + '.' + ENTITY_TYPE),
      pageCode: MODULE_CODE + ':' + ENTITY_TYPE + ':',
      entityData: {
        organizationId: this.parentId,
        organizationName: this.parentName,
        parentId: this.parentId,
        parentName: this.parentName
      },
      rules: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ],
        account: [
          { required: true, message: '请输入账号', trigger: 'blur' }
        ],
        gender: [
          { required: true, message: '请选择性别', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '请选择状态', trigger: 'blur' }
        ]
      },
      currentRow: {}
    }
  },
  watch: {
    parentId: function () {
      this.entityData.organizationId = this.parentId
      this.entityData.organizationName = this.parentName
    },
    'entityData.parentName': function () {
      if (this.mode === 'add') {
        this.entityData.organizationId = this.entityData.parentId
        this.entityData.organizationName = this.entityData.parentName
      }
    }
  },
  methods: {
    changeSelect(value, name) {
      this.entityData.organizationId = value
      this.entityData.organizationName = name
    }
  }

}
</script>

<style lang="scss">
</style>
